package my.sample.quartz.datamap;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataMap {

	private static Logger log = null;
	
	public static void main(String[] args) throws SchedulerException, InterruptedException {

		log = LoggerFactory.getLogger(DataMap.class);
		
		SchedulerFactory fact = new StdSchedulerFactory();
		Scheduler scheduler = fact.getScheduler();
		System.out.println("scheduler name: " + scheduler.getSchedulerName());
		scheduler.start();
		
		JobDetail job = newJob(SimpleJob.class).withIdentity("null", "null").build();
		
		job = job.getJobBuilder().withIdentity("myFirst", "myGroup").build();
		job.getJobDataMap().put("one", "1");
		job.getJobDataMap().put("other", "other");
		CronTrigger trigger = newTrigger().withIdentity("myFirst", "myGroup").withSchedule(cronSchedule("0/2 * * ? * *")).build();
		System.out.println("job hash 1 : " + job.hashCode());
		scheduler.scheduleJob(job, trigger);
		
		CronTrigger trigger1 = newTrigger().withIdentity("mySecond", "myGroup").withSchedule(cronSchedule("0/3 * * ? * *")).build();
		job.getJobDataMap().put("one", "2");
		job = job.getJobBuilder().withIdentity("mySecond", "myGroup").build();
		System.out.println("job hash 2 : " + job.hashCode());		
		scheduler.scheduleJob(job, trigger1);
		
		CronTrigger trigger2 = newTrigger().withIdentity("myThird", "myGroup").withSchedule(cronSchedule("0/3 * * ? * *")).build();
		job = job.getJobBuilder().withIdentity("myThird", "myGroup").build();
		job.getJobDataMap().put("one", "3");
		System.out.println("job hash 3 : " + job.hashCode());		
		scheduler.scheduleJob(job, trigger2);
		
		log.info("Jobs are scheduled...");
	}

}
